/**
 * 使用样例
 * 定义
 * uploadingdialog = new CustomLoadingDialog(WritePaperActivity.this,"正在上传...");
 *显示、消失
 * if(uploadingdialog.isShowing()){
		uploadingdialog.dismiss();
	}else{
		uploadingdialog.show();
	}
 */
package com.newworld.dmsapp2.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.newworld.dmsapp2.R;

/**
 * 得到自定义的progressDialog
 * 
 * @param context
 * @param msg
 * @return
 */
public class CustomLoadingDialog {

	Context context;
	private Dialog loadingDialog;

	// 对话框事件监听接口，用于处理回调点击事件
	public interface LoadingDialogListener {
		public void onClick(View view);
	}

	@SuppressWarnings("deprecation")
	public CustomLoadingDialog(Context context, String msg) {
		// TODO Auto-generated constructor stub
		this.context = context;
		loadingDialog = new Dialog(context, R.style.loading_dialog);// 创建自定义样式dialog
		LayoutInflater inflater = LayoutInflater.from(context);

		View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
		Window window = loadingDialog.getWindow();
		window.setContentView(v);

		v.setEnabled(false);
		v.setClickable(false);
		LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
		// main.xml中的ImageView
		ImageView spaceshipImage = (ImageView) window.findViewById(R.id.img);
		TextView tipTextView = (TextView) window.findViewById(R.id.tipTextView);// 提示文字
		// 加载动画
		Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
				context, R.anim.loading_animation);
		// 使用ImageView显示动画
		spaceshipImage.startAnimation(hyperspaceJumpAnimation);
		tipTextView.setText(msg);// 设置加载信息

		loadingDialog.setCancelable(false);// 不可以用“返回键”取消
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.FILL_PARENT));// 设置布局
	}

	public void show() {
		loadingDialog.show();
	}

	public void dismiss() {
		loadingDialog.dismiss();
	}

	public boolean isShowing() {
		return loadingDialog.isShowing();
	}

	public void setCancelable(boolean d) {
		loadingDialog.setCancelable(d);
	}
}
